from django.db import models
from users.models import BaseModel, User
from django_mysql.models import JSONField

# Create your models here.
class Moment(BaseModel):
    user = models.ForeignKey(User, related_name='m_master', on_delete=models.CASCADE, verbose_name='用户')
    data = models.CharField(max_length=500 ,null=True, blank=True, verbose_name='所说的话')
    img_data = JSONField(null=True, blank=True ,verbose_name='文件信息(图片)')
    date = models.DateTimeField(default='2021-01-01 00:00:00', verbose_name='发布时间')
    dz_num = models.IntegerField(default=0, verbose_name='点赞数')
    pl_num = models.IntegerField(default=0, verbose_name='评论数')

    class Meta:
        db_table = 'tb_moment'
        verbose_name = '朋友圈数据'
        verbose_name_plural = verbose_name

class MomentImage(BaseModel):
    moment = models.ForeignKey(Moment, on_delete=models.CASCADE, related_name='m_img', verbose_name='朋友圈图片')
    image_src = models.CharField(max_length=160,verbose_name='图片地址')
    order = models.IntegerField(null=True,blank=True, verbose_name='图片排序')

    class Meta:
        db_table = 'tb_m_image'
        verbose_name = '朋友圈图片数据'
        verbose_name_plural = verbose_name

class MomentPl(BaseModel):
    monment = models.ForeignKey(Moment, on_delete=models.CASCADE, related_name='moment', verbose_name='所在朋友圈')
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='friend_say', verbose_name='朋友')
    data = models.CharField(max_length=500, verbose_name='内容')
    to_user = models.ForeignKey('self', null=True, blank=True, related_name='subs', on_delete=models.CASCADE, verbose_name='回复给谁')

    class Meta:
        db_table = 'tb_moment_pl'
        verbose_name = '朋友圈踩楼'
        verbose_name_plural = verbose_name


